﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PlatWL.Models;
using Nancy.Security;
using System.IO;
using PlatWL.Services.Services;

namespace PlatWL.Models
{
    public class UserMapper
    {
        public static IUserIdentity GetUserFromAccessToken(string token)
        {

            if (string.IsNullOrEmpty(token))
            {
                return null;
            }

            var ue = new UserIdentity();

            if (!string.IsNullOrEmpty(token))
            {
                var userToken = new AuthManage().GetToken(token);
                if (userToken != null)
                {
                    ue.Client = userToken.Client.Value;
                    ue.UserID = userToken.UserID.Value;
                    ue.UserName = userToken.UserID.ToString(); //nancy根据此字段判断是否授权登录
                    ue.ISAdmin = userToken.ISAdmin.Value;

                }
                else
                {
                    //clear cookie
                }
            }
            return ue;
        }
    }


}